<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

</head>
<body>
    <button>GET</button>
    <button>POST</button>

    <script>
        //获取按钮
        let btns = document.querySelectorAll('button');

        //绑定事件 GET
        btns[0].onclick =async function(){
            //发送 GET 请求                      配置对象
            // let result = await axios.get(url, config);
            let result = await axios.get('http://127.0.0.1:8023/server', {
                params: {
                    name: 'zhangsan',
                    age: 30
                }
            });
            console.log(result);
        }

        btns[1].onclick = async function(){
            //发送 POST 请求                      请求体   配置对象
            // let result = await axios.post(url, data,   config);
            let result = await axios.post(
                'http://127.0.0.1:8023/server',  // URL
                {username: 'wangwu', password: '12h1ou3hj12i31'}, //请求体 
                {
                    params: {
                        a: 100,
                        b: 200
                    }
                }
            )
            //打印结果
            console.log(result);
        }

        // axios.get   axios.delete    (url, config)
        // axios.post  axios.put  axios.patch   (url, data, config)

    </script>
</body>
</html>